/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upc.clase.demo.dao.impl;

import edu.upc.clase.demo.dao.LocalDao;
import edu.upc.clase.demo.entity.Local;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.stereotype.Repository;
/**
 *
 * @author Omar
 */
@Repository
public class LocalDaoImpl extends SimpleJdbcDaoSupport implements LocalDao{

    private static Logger log = LoggerFactory.getLogger(LocalDaoImpl.class);

    @Autowired
    public LocalDaoImpl(DataSource dataSource) {
        log.info("Asignando el dataSource");
        setDataSource(dataSource);
    }

    @Override
    public int registrar(Local local) {
        getJdbcTemplate().update("insert into ZREGLOCAL(CODDIST, IDPERS, TIPPERS, LNOMBRE, LDIRECC, LDIRECG, LTELEF) "
                + " values (?,?,?,?,?,?,?)", local.getCODDIST(), local.getIDPERS(), local.getTIPPERS(),
                local.getLNOMBRE(), local.getLDIRECC(), local.getLDIRECG(),local.getLTELEF());
        return getSimpleJdbcTemplate().queryForInt("call identity()");
    }

}
